﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model ShenNius.Share.Models.Entity.Sys.Tenant
@section css{
    <style>
        .layui-form-item .layui-input {
            width: 350px;
            padding-right: 10px;
            line-height: 38px;
        }

        .layui-form-item .layui-textarea {
            width: 350px;
        }

        .layui-form-select {
            width: 350px;
        }

        .layui-upload-img {
            width: 135px;
            height: 95px;
            padding-left: 110px;
        }
    </style>
}

<form id="siteForm" class="layui-form" action="" lay-filter="config-edit">
    <div class="layuimini-container layuimini-page-anim">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form">
                <div class="baseInfo">
                    @if (Model.Id > 0)
                    {
                        <div class="layui-form-item">
                            <label class="layui-form-label">编号</label>
                            <div class="layui-input-block">
                                <input type="text" name="id" lay-verify="id" value="@Model.Id" disabled class="layui-input">
                            </div>
                        </div>
                    }
                    <div class="layui-form-item">
                        <label class="layui-form-label" required>站点名称:</label>
                        <div class="layui-input-block">
                            <input type="text" placeholder="请填写站点名称" lay-verify="name" name="name" class="layui-input" value="@Model.Name" required />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">站点域名:</label>
                        <div class="layui-input-block">
                            <input type="text" name="url" placeholder="请填写入站点域名" value="@Model.Url" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">版权:</label>
                        <div class="layui-input-block">
                            <input type="text" name="copyright" placeholder="请填写版权" value="@Model.Copyright" class="layui-input" lay-verify="copyright">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">联系邮箱:</label>
                        <div class="layui-input-block">
                            <input type="text" name="email" placeholder="请填写入联系邮箱" value="@Model.Email" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题:</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" placeholder="请填写入站点标题" value="@Model.Title" class="layui-input" lay-verify="title" required>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">关键字:</label>
                        <div class="layui-input-block">
                            <input type="text" name="keyword" placeholder="请填写入站点关键字" value="@Model.Keyword" class="layui-input" lay-verify="keyword" required>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">描述:</label>
                        <div class="layui-input-block">
                            <textarea name="description" placeholder="请输入备注" value="@Model.Description" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否关闭</label>
                        <div class="layui-input-block">
                            @if (Model.Status)
                            {
                                <input type="checkbox" checked name="status" value="true" lay-skin="switch">
                            }
                            else
                            {
                                <input type="checkbox" name="status" value="false" lay-skin="switch">
                            }
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">关闭原因:</label>
                        <div class="layui-input-block">
                            <textarea name="closeInfo" placeholder="请输入关闭原因" value="@Model.CloseInfo" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>

                <div class="otherInfo" style="display:none;">
                    <div class="layui-form-item">
                        <label class="layui-form-label">公司电话:</label>
                        <div class="layui-input-block">
                            <input type="text" name="tel" placeholder="请填写入公司电话" value="@Model.Tel" class="layui-input" lay-verify="tel">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">公司传真:</label>
                        <div class="layui-input-block">
                            <input type="text" name="fax" placeholder="请填写入公司传真" value="@Model.Fax" class="layui-input" lay-verify="fax">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">联系地址:</label>
                        <div class="layui-input-block">
                            <input type="text" name="address" placeholder="请填写入公司联系地址" value="@Model.Address" class="layui-input" lay-verify="address">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">客服QQ:</label>
                        <div class="layui-input-block">
                            <input type="text" name="qQ" placeholder="请填写入公司客服QQ" value="@Model.QQ" class="layui-input" lay-verify="qQ">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">备注:</label>
                        <div class="layui-input-block">
                            <textarea name="summary" placeholder="请输入备注" value="@Model.Summary" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">微信:</label>
                        <div class="layui-upload">
                            <button type="button" class="layui-btn" id="test1">上传图片</button>
                            <div class="layui-upload-list">
                                @if (!string.IsNullOrEmpty(Model.WeiXin))
                                {
                                    <img class="layui-upload-img" id="demo1" src="@Model.WeiXin">
                                    <input type="hidden" id="weiXin" name="weiXin" class="layui-input" value="@Model.WeiXin">
                                }
                                else
                                {
                                    <img class="layui-upload-img" id="demo1">
                                    <input type="hidden" id="weiXin" name="weiXin" class="layui-input">
                                }
                                <p id="demoText"></p>
                            </div>

                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">微博:</label>
                        <div class="layui-input-block">
                            <input type="text" name="weiBo" placeholder="请填写入公司微博" value="@Model.WeiBo" class="layui-input" lay-verify="weiBo">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block" style="display:inline-flex;">
                        <button type="button" class="layui-btn layui-btn-normal" id="next" lay-submit lay-filter="formStep">下一步</button>
                        <button type="button" class="layui-btn layui-btn-normal" id="up" lay-submit lay-filter="formStep2" style="display:none">
                            上一步
                        </button>
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>


@section js{
    <script>
        layui.use(['form', 'common', 'upload'], function () {
            var $ = layui.$,
                form = layui.form,
                upload = layui.upload,
                apiUtil = layui.common;
            $(function () {
                $("#next").click(function () {
                    $(".baseInfo").css("display", "none");
                    $(".otherInfo").css("display", "block");//
                    $("#up").css("display", "block");
                    $("#next").css("display", "none");
                });
                $("#up").click(function () {
                    $(".baseInfo").css("display", "block");
                    $(".otherInfo").css("display", "none");
                    $("#up").css("display", "none");
                    $("#next").css("display", "block");
                });
            });

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                , url: apiUtil.apiUrl() + 'tenant/qiniuFile' //改成您自己的上传接口
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    if (res.statusCode == 200 && res.success == true) {
                        $('#demo1').attr('src', res.data);
                        $('#weiXin').val(res.data);
                        console.log("img:" + res.data);
                    }
                    //上传成功
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
            // 当前弹出层，防止ID被覆盖
            var parentIndex = parent.layer.getFrameIndex(window.name);
            form.on('submit(saveBtn)', function (data) {
                if (data.field.id > 0) {
                    apiUtil.ajax('tenant/modify', data.field, "application/json", "put", function (res) {
                        if (res.statusCode == 200 && res.success == true) {
                            apiUtil.success(res.msg);
                            parent.layer.close(parentIndex);
                        } else {
                            apiUtil.error(res.msg);
                        }
                    });
                } else {
                    apiUtil.ajax('tenant/add', data.field, "application/json", "post", function (res) {
                        if (res.statusCode == 200 && res.success == true) {
                            apiUtil.success(res.msg);
                            parent.layer.close(parentIndex);
                        } else {
                            apiUtil.error(res.msg);
                        }
                    });
                }
                return false;
            });
        })
    </script>
}

